
package com.compuvest.ajax;

// <editor-fold defaultstate="collapsed" desc="import">
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.compuvest.web.SQLBean;
// </editor-fold>

public class DescTabs extends HttpServlet {

    private SQLBean mysql;

// <editor-fold defaultstate="collapsed" desc="init()">

    @Override
    public void init(ServletConfig config) throws ServletException {
	super.init(config);

        mysql = (SQLBean)config.getServletContext().getAttribute("sb");
	if(mysql == null) {
            System.out.println("DescTabs Error sb=null");
        }
        System.out.println("DescTabs init");
    }

// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="processRequest()">

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)  throws ServletException, IOException {

        response.setContentType("text/html;charset=UTF-8");

        String mfrs = request.getParameter("mfrs");
	if(mfrs != null && mfrs.length() > 0) {

            StringBuilder result = new StringBuilder();
            try {
                int idx = 0;
                for(String token : mfrs.split("\\,")) {
                    result.append(idx++ > 0 ? "," : "").append('\'').append(token).append('\'');
                }
            }
            catch(Exception ignore) { }


            String items = mysql.getTabsProducts(result.toString());
//            System.out.println("###items="+items);
/*            if("tb01".equals(tab)) { // Overview
            }
            else if("tb02".equals(tab)) { // Technical Specification
            }
            else if("tb03".equals(tab)) { // Option & Accessories
		desc = mysql.getTabsProducts(etilid);
            }
            else if("tb04".equals(tab)) { // Simular product
		desc = mysql.getTabsProducts(etilid);
            }*/

            PrintWriter out = response.getWriter();
            try {
		out.print(items);
            }
            finally {
		out.close();
            }
	}
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods.">

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }
    @Override
    public String getServletInfo() {
        return "DescTabs";
    }
    @Override
    public void destroy() {
        mysql = null;
	System.out.println("DescTabs Destroy:");
    }
// </editor-fold>

}
